< previous page page_402 next page >

Page 402
Creating the MDI Parent Template
The MDI parent form is the keeper (or container) of the child windows, so it is responsible for creating new children. With this duty, it is common for the parent to also keep track of the number of child windows it has created. In addition, the parent usually holds shared user interface elements like a toolbar, status bar, and so on.
The code in Listing 17.6 shows the code used to maintain and expose the window count. WindowCreate and WindowDestroyed are called by the child windows in their Form_Load and Form_Unload event procedures, respectively. ChildWindowCount is a Public property that allows the child windows to find out how many children are loaded.
Listing 17.6 MDIPARENT.TXTUse the Parent to Contain Common Code for All the Child Forms

'*********************************************************************
' MDIParent.frm - Demonstrates some basic concepts on how a MDI parent
'   form should behave in an MDI application.
'*********************************************************************
Option Explicit
Private mintChildWinCount As Integer
'*********************************************************************
' Returns how many child windows have been created
'*********************************************************************
Public Property Get ChildWindowCount() As Integer
    ChildWindowCount = mintChildWinCount
End Property
'*********************************************************************
' Called when a window is created to increment the window counter
'*********************************************************************
Public Sub WindowCreated()
    mintChildWinCount = mintChildWinCount + 1
    UpdateButtons True
End Sub
'*********************************************************************
' Called when a window is created to decrement the window counter
'*********************************************************************
Public Sub WindowDestroyed()
    mintChildWinCount = mintChildWinCount - 1
    UpdateButtons mintChildWinCount
End Sub
You also might notice a call to UpdateButtons in Listing 17.6. This private helper routine enables and disables toolbar buttons. If children exist, then the toolbar buttons are enabled. When the last child is unloaded, WindowDestroyed decrements the variable mintChildWinCount to 0, which causes UpdateButtons to disable the toolbar buttons.
The most important code in MDIPARENT.FRM is the File menu's Click event procedure. This code is responsible for creating windows, opening files, and terminating the application.

 
< previous page page_402 next page >